// 修复http-proxy-middleware模块热替换导致createProxyMiddleware等函数丢失的问题
import httpProxyMiddleware, {
  Filter,
  Options,
  RequestHandler
} from 'http-proxy-middleware'

let createProxyMiddleware: typeof httpProxyMiddleware.createProxyMiddleware,
  responseInterceptor: typeof httpProxyMiddleware.responseInterceptor,
  fixRequestBody: typeof httpProxyMiddleware.fixRequestBody

if (__DEV__) {
  ;(global as any)._httpProxyMiddleware =
    (global as any)._httpProxyMiddleware ?? httpProxyMiddleware
  ;({ createProxyMiddleware, responseInterceptor, fixRequestBody } = (
    global as any
  )._httpProxyMiddleware)
} else {
  ;({ createProxyMiddleware, responseInterceptor, fixRequestBody } =
    httpProxyMiddleware)
}

export {
  createProxyMiddleware,
  Filter,
  Options,
  RequestHandler,
  responseInterceptor,
  fixRequestBody
}
